package com.bawei.play.model


import com.bawei.common.entity.SimpleVideoEntity
import com.bawei.common.model.BaseRepository
import com.bawei.play.api.PlayServerApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

/**
 * Author: Jason Zhang
 * Date: 2025/1/16
 * Desc: 视频播放数据仓库
 */
class PlayRepository @Inject constructor(private val apiServer: PlayServerApi): BaseRepository<PlayServerApi>(){

    suspend fun getSimpleVideoByChannelId(channelId: String, page: Int, pageSize: Int): Flow<List<SimpleVideoEntity>> {
        return flow {
            var result = apiServer.getSimpleVideoByChannelId(channelId, page, pageSize)
            if (result.code == 0){
                emit(result.data)
            }else{
                emit(listOf())
            }
        }
    }

    suspend fun getRecommendVideo(page: Int, pageSize: Int): Flow<List<SimpleVideoEntity>>{
        return flow {
            var result = apiServer.getRecommendSimpleVideo(page, pageSize)
            if (result.code == 0){
                emit(result.data)
            }else{
                emit(listOf())
            }
        }
    }


}